import {
	createRouter,
	createWebHistory
} from 'vue-router'

const router = createRouter({
	history: createWebHistory(import.meta.env.BASE_URL),
	routes: [
		// 默认请求，重定向到login界面
		{
			path: '/',
			redirect: '/login'
		},
		// 登陆组件的路由，使用懒加载
		{
			path: '/login',
			name: 'login',
			component: () => import('@/views/Login.vue')
		},
		//后台页面
		{
			path: '/index',
			name: 'index',
			component: () => import('@/views/Index.vue'),
			redirect: '/welcome',
			children: [
				// 欢迎界面
				{
					path: '/welcome',
					name: 'welcome',
					component: () => import('@/views/Welcome.vue')
				},
				//系统管理-用户管理
				{
					path: '/user',
					name: 'user',
					component : ()=> import('@/views/system/User.vue')
				},
				//系统管理-角色管理
				{
					path: '/character',
					name: 'character',
					component : ()=> import('@/views/system/Character.vue')
				},
				//系统管理-菜单管理
				{
					path: '/menu',
					name: 'menu',
					component : ()=> import('@/views/system/Menu.vue')
				},
				//系统管理-公司管理
				{
					path: '/company',
					name: 'company',
					component : ()=> import('@/views/system/Company.vue')
				},
				//课程管理-分类管理
				{
					path:'/classify',
					name:'classify',
					component:()=> import('@/views/course/Classify.vue')
				},
				//课程管理-课程管理
				{
					path:'/course',
					name:'course',
					component:()=> import('@/views/course/Course.vue')
				},
				//课程管理-视频管理
				{
					path:'/video',
					name:'video',
					component:()=> import('@/views/course/Video.vue')
				},
				//课程管理-评价管理
				{
					path:'/appraise',
					name:'appraise',
					component:()=> import('@/views/course/Appraise.vue')
				},
				//课程管理-订单管理
				{
					path:'/courseorder',
					name:'courseorder',
					component:()=> import('@/views/course/CourseOrder.vue')
				},
				//咨询师管理
				{
					path:'/info',
					name:'info',
					component:()=> import('@/views/counselor/Info.vue')
				},
				// 咨询师管理-擅长领域管理
				{
					path:'/specialism',
					name:'specialism',
					component:()=> import('@/views/counselor/Specialism.vue')
				},
				// 咨询师管理-留言管理
				{
					path:'/message',
					name:'message',
					component:()=> import('@/views/counselor/Message.vue')
				},
				// 咨询师管理-评价管理
				{
					path:'/evaluate',
					name:'evaluate',
					component:()=> import('@/views/counselor/Evaluate.vue')
				},
				// 咨询师管理-等级管理
				{
					path:'/level',
					name:'level',
					component:()=> import('@/views/counselor/Level.vue')
				},
				// 咨询师管理-收费分类管理
				{
					path:'/consultantclassification',
					name:'consultantclassification',
					component:()=> import('@/views/counselor/Classification.vue')
				},
				// 咨询师管理-订单管理
				{
					path:'/order',
					name:'order',
					component:()=> import('@/views/counselor/Order.vue')
				},
				// 咨询师管理-收费标准管理
				{
					path:'/standard',
					name:'standard',
					component:()=> import('@/views/counselor/Standard.vue')
				},
				//内容管理-文章管理
				{
					path: '/articlemanagement',
					name: 'articlemanagement',
					component: () => import('@/views/content/ArticleManagement.vue')

				},
				//内容管理-FM分类
				{
					path: '/fmclassificationmanagement',
					name: 'fmclassificationmanagement',
					component: () => import('@/views/content/FMClassificationManagement.vue')

				},
				// 内容管理-FM管理
				{
					path: '/fmmanagement',
					name: 'fmmanagement',
					component: () => import('@/views/content/FMManagement.vue')

				},
				// 内容管理-文章分类
				{
					path: '/classification',
					name: 'classification',
					component: () => import('@/views/content/Classification.vue')

				},
				// 内容管理-公益中心
				{
					path: '/welfarecenters',
					name: 'welfarecenters',
					component: () => import('@/views/content/WelfareCenters.vue')

				},
				// 内容管理-心理知识
				{
					path: '/psyknowledge',
					name: 'psyknowledge',
					component: () => import('@/views/content/PsyKnowledge.vue')

				},
				// 内容管理-文章回收
				{
					path: '/articlerecycle',
					name: 'articlerecycle',
					component: () => import('@/views/content/ArticleRecycle.vue')

				},
				// 咨询预约
				{
					path: '/consultbooking',
					name: 'consultbooking',
					component: () => import('@/views/ConsultBooking.vue')
				},
				// 咨询公告
				{
					path: '/inforbulletin',
					name: 'inforbulletin',
					component: () => import('@/views/InforBulletin.vue')
				},
				// 积分管理
				{
					path: '/integraimanage',
					name: 'integraimanage',
					component: () => import('@/views/IntegralManage.vue')
				},
				// 心理答疑-问题管理
				{
					path: '/questionmanage',
					name: 'questionmanage',
					component: () => import('@/views/questions/QuestionManage.vue')
				},
				// 心理答疑-问题回复
				{
					path: '/replymanage',
					name: 'replymanage',
					component: () => import('@/views/questions/ReplyManage.vue')
				},
				// 心理测评-测评分类
				{
					path: '/testclassification',
					name: 'testclassification',
					component: () => import('@/views/knowledgetest/TestClassification.vue')
				},
				// 心理测评-测评题库
				{
					path: '/testbank',
					name: 'testbank',
					component: () => import('@/views/knowledgetest/TestBank.vue')
				},
				//心理测评题目管理
				{
					path:'/testtopic',
					name: 'testtopic',
					component:()=>import('@/views/knowledgetest/TestTopic.vue')
				},
				//心理测评结果管理
				{
					path:'/testanswer',
					name: 'testanswer',
					component:()=>import('@/views/knowledgetest/TestAnswer.vue')
				}
			]
		},
	],
})

// // 前置路由首位，每次路由跳转都要执行beforeEach里面的函数
// 前置路由首位，每次路由跳转都要执行beforeEach里面的函数
/* router.beforeEach((to, from, next) => {
	// 只有登陆页面，无需登录即可访问，其他页面都需要登录才能访问，如果没有登录，则跳转到登陆页面
	if (to.path == '/login') {
		return next()
	}

	//判断是否登录
	const loginUser = sessionStorage.getItem('loginUser')
	//如果会话框里面保存的内容为空，则说明未登陆成功，返回登陆界面
	if (!loginUser) {
		return next('/login')
	} else {
		//放行
		next()
	}
	return false
}) */
export default router